<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
   let dec2bin = (decNumber) => {
    //1.定义一个栈对象，保存余数
    var stack = new Stack();

    // 2.循环操作
    while (decNumber > 0) {
        // 2.1.获取余数并放入栈中
        stack.push(decNumber % 2);
        // 2.2.获取整除后的结果作为下一次运算的数字(floor:向下取整)
        decNumber = Math.floor(decNumber / 2);
    }

    // 3.从栈中取出0和1
    let binaryString = "";
    let a = stack.items.length;
    while (stack.items.length != 0) {
        binaryString += stack.pop();
    }
    return binaryString;
};




function generatePrintBinary(n) {
    let q = new Queue()
    q.enqueue('1')
    while (n-- > 0) {
      let s1 = q.front()
      q.dequeue()
      console.log(s1)
      let s2 = s1
      q.enqueue(s1 + '0')
      q.enqueue(s2 + '1')
    }
  }
  
  generatePrintBinary(5) // => 1 10 11 100 101

  </script>
</body>
</html>